//
//  XMSendStatusToolView.m
//  XMWeibo
//
//  Created by chi on 14-8-29.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMSendStatusToolBar.h"




@implementation XMSendStatusToolBar


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage adaptIOS7ImageWithName:@"compose_toolbar_background"]];
        
        //相机
        [self addButtonWithImageNormal:@"compose_camerabutton_background" highlighted:@"compose_camerabutton_background_highlighted" tag:kSendStatusToolButtonCamera];
        
        // 图片
        [self addButtonWithImageNormal:@"compose_toolbar_picture" highlighted:@"compose_toolbar_picture_highlighted" tag:kSendStatusToolButtonPiture];
        
        // @
        [self addButtonWithImageNormal:@"compose_mentionbutton_background" highlighted:@"compose_mentionbutton_background_highlighted" tag:kSendStatusToolButtonMention];
        
        //#
        [self addButtonWithImageNormal:@"compose_trendbutton_background" highlighted:@"compose_trendbutton_background_highlighted" tag:kSendStatusToolButtonTrend];
        
        //表情
        [self addButtonWithImageNormal:@"compose_emoticonbutton_background" highlighted:@"compose_emoticonbutton_background_highlighted" tag:kSendStatusToolButtonEmoticon];

        
        
        
    }
    return self;
}

/**
 *  创建按钮
 */
- (void)addButtonWithImageNormal:(NSString*)normal highlighted:(NSString*)highlighted tag:(NSUInteger)tag
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage adaptIOS7ImageWithName:normal] forState:UIControlStateNormal];
    [button setImage:[UIImage adaptIOS7ImageWithName:highlighted] forState:UIControlStateHighlighted];
    button.tag = tag;
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:button];
}


- (void)clickButton:(UIButton*)button
{
    if ([self.delegate respondsToSelector:@selector(clickToolButton:)]) {
        [self.delegate clickToolButton:button.tag];
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    NSInteger count = self.subviews.count;
    
    CGFloat btnW = self.bounds.size.width / count;
    CGFloat btnH = self.bounds.size.height;
    CGFloat btnY = 0.0;
    CGFloat btnX = 0.0;
    for (int i = 0; i < count; ++i) {
        UIButton *btn = self.subviews[i];
        btnX = i * btnW;
        btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
    }
    
}






@end
